package com.tyqx.hashchainbiz.service.impl;

import com.tyqx.hashchainbean.test.BaiWanTest;
import com.tyqx.hashchainbean.test.Test;
import com.tyqx.hashchainbiz.service.TestService;
import com.tyqx.hashchaindao.mapper.TestMapper;
import hashchainutil.common.BackendPage;
import hashchainutil.common.Constants;
import hashchainutil.common.EmptyUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("testService")
public class TestServiceImpl implements TestService {

    @Resource
    private TestMapper testMapper;

    @Override
    public Integer insertTest(Test test) {
        return testMapper.insertTest(test);
    }

    @Override
    public List<String> getJsonStringByHashValue(String hashValue) {
        return testMapper.getJsonStringByHashValue(hashValue);
    }

    @Override
    public Integer getHashValueCount(String hashValue) {
        return testMapper.getHashValueCount(hashValue);
    }

    @Override
    public List<Test> getTestTable(String hashValue) {
        return testMapper.getTestTable(hashValue);
    }

    @Override
    public List<String> getHashValueList(String rootHashValue) {
        return testMapper.getHashValueList(rootHashValue);
    }

    @Override
    public BackendPage<List<Test>> queryAll(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = testMapper.queryAllCount();
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        param.put("beginPos", (pageNo - 1) * pageSize);
        param.put("pageSize", pageSize);
        List<Test> testList = testMapper.queryAll(param);
        BackendPage page = new BackendPage(total, testList);
        return page;
    }


}
